#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2,re,os,cookielib,xbmc

#author:
#elypter (elypter@yahoo.de)
#FreaX
#
#for details look at default.py
#version: 0.1
#date: 20100504 

def check(url):
	if url.rfind("duckload") or url.rfind("youload"):
		return 1
	else:
		return 0

def get_regexp():
	return "(http://duckload.com(?:/divx){0,1}/[0-9a-zA-Z]*.html|http://youload.to(?:/divx){0,1}/[0-9a-zA-Z]*.html)"
def get_name():
	return "duckload"
def join(id):
	return id
	
def get_link1(url):
	#takes an videopage-url of duckload
	#
	#returnes the service/mirror name, the url that will be passed over to get_link2, the url of the verification code
	if url.rfind("duckload.com") != -1:
		domain="duckload.com"
	elif url.rfind("youload.to") != -1:
		domain="youload.to"
	else:
		print "error"
		
	BASE_PATH = os.getcwd().replace( ";", "" )
	BASE_DATA_PATH = os.path.join( xbmc.translatePath("special://profile/plugin_data/hoster"), "oracle2" )

	data = urllib.urlencode({"server": 1, "sn": "Stream Starten"})	
	req = urllib2.Request(url, data)
	req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2')
	req.add_header("Referer", url)
	response = urllib2.urlopen(req)
	page=response.read()
	response.close()
	
	link = re.compile('type="video/divx" src="([^<>"]*)"',re.I|re.DOTALL).findall(page)
	
	if link!=None and len(link)>0:
		return ("got",link[0],'','','','','duckload')
	else:
		return ("fail",'','','','','','duckload')

	
def get_link2(param,code):
		return ("got",param,'','','','','duckload')